import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:ls_work/ui/select_employee_page.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'package:ls_work/viewmodel/select_temp_human_view_model.dart';

import '../res/colors.dart';

class SelectTempHumanPage extends BaseStatefulMvvmWidget {

  Function(SelectFoodHuman human)? onSelectListener;


  SelectTempHumanPage({this.onSelectListener});

  @override
  State<StatefulWidget> createState() => _SelectTempHumanState();

}

class _SelectTempHumanState
    extends BaseMvvmListState<SelectTempHumanViewModel, SelectTempHumanPage> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: AppBar(title: Text("选择临时人员"),),
      body: Column(
        children: [
          // CommonInput(
          //   isDense: true,
          //   border: InputBorder.none,
          //   padding: EdgeInsets.zero,
          //   hintText: '请输入姓名或者首字母搜索',
          //   textInputAction: TextInputAction.search,
          //   onSubmitted: (str) {
          //     viewModel.requestRefresh(showAni: true);
          //   },
          //   onChanged: (str) {
          //     viewModel.nameLike = str;
          //   },
          // ).addToContainer(
          //     margin: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
          //     padding: EdgeInsets.all(10),
          //     decoration: BoxDecoration(
          //         color: Colors.white, borderRadius: 4.borderRadius)
          // ),
          loadingContentWidget.setWeight(1)
        ],
      ),
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            CommonText(item.humanName, textSize: 17, fontWeight: FontWeight.bold),
            CommonText('临时人员', textColor: Colours.app_main)
          ],
        ),
        Container(height: 10,),
        CommonText('余额：${item.balMoney??0}')
      ],
    ).onTap(() {
      if(widget.onSelectListener!=null){
        var human = SelectFoodHuman(type: 1,
            name: item.humanName,
            id: item.humanId.toStringOrNull());
        widget.onSelectListener!(human);
      }
    }).addToContainer(
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: 8.borderRadius),
        padding: EdgeInsets.all(10),
        margin: EdgeInsets.symmetric(horizontal: 16)
    );
  }

  @override
  Widget get separatorDivider => Container(height: 10,);

  @override
  SelectTempHumanViewModel createViewModel() {
    return SelectTempHumanViewModel(context);
  }

}